package com.lwb.ztx.news.widget;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lwb.ztx.R;
import com.lwb.ztx.bean.NewsBean;
import com.lwb.ztx.utils.ActivitySkipUtils;
import com.lwb.ztx.utils.ImageLoaderUtils;
import com.lwb.ztx.utils.LogUtils;

/**
 * A simple {@link Fragment} subclass.
 */
@SuppressLint("ValidFragment")
public class NewsImageFragment extends Fragment {

    String url;
    NewsBean bean;
    public NewsImageFragment() {
        // Required empty public constructor
    }
    public NewsImageFragment(String url) {
        // Required empty public constructor
        this.url = url;
    }
    public NewsImageFragment(NewsBean bean) {
        // Required empty public constructor
        this.bean = bean;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        ImageView view;
        if (null != url) {
            view = (ImageView) inflater.inflate(R.layout.fragment_news_image, container, false);
            ImageLoaderUtils.display(this.getActivity(), view,url);
            LogUtils.d("NewsImageFragment load image: " + url);
        } else if (bean != null) {
            view = (ImageView)inflater.inflate(R.layout.fragment_news_image_slider, container, false);
            ImageLoaderUtils.display(this.getActivity(), view,bean.getThumbnail());
            LogUtils.d("NewsImageFragment load image: " + bean.getThumbnail());
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ActivitySkipUtils.readNews(NewsImageFragment.this.getActivity(), bean);
                }
            });
        } else {
            view = (ImageView)inflater.inflate(R.layout.fragment_news_image, container, false);
        }
        return view;
    }

}
